// pages/address/address.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    msglists: [],
    chose:false,
    choselists:null
  },

  chose(e){
    console.log(e.currentTarget.dataset.id)
    let isit =  this.data.msglists.findIndex(item=>(item.id == e.currentTarget.dataset.id))
    console.log(isit)
    let ta = this.data.msglists[isit]
    this.setData({
      choselists:ta
    })
    wx.setStorageSync('choselists', this.data.choselists)
    wx.navigateBack({
      delta: 1
    })
  },


 //跳转
  gowrite() {
    // console.log("xxx");
    wx.navigateTo({
      url: '/pages/write/write',
    })
  },
  //删除
  del(e){
    // console.log(e.currentTarget.dataset.index)
    console.log(e.currentTarget.dataset.id)
    let delitem =  this.data.msglists.findIndex(item=>(item.id == e.currentTarget.dataset.id))
    console.log(delitem)
    this.data.msglists.splice(delitem,1)
    if(!this.data.msglists){
      this.data.choselists=""
    }
    wx.setStorageSync('choselists', this.data.choselists)
    this.setData({
      msglists: this.data.msglists,
      choselists:this.data.choselists
    })
    wx.setStorageSync('choselists', this.data.choselists)
    wx.setStorageSync('msglists', this.data.msglists)
    
    
    // msglists.splice(index,1)
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // let name = wx.getStorageSync('name')
    // let num = wx.getStorageSync('num')
    // let where = wx.getStorageSync('where')
    // let home = wx.getStorageSync('home')
    // console.log(name,num,where,home)
    // this.setData({

    // })
    // console.log(this.data.msg)



    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let msglists = wx.getStorageSync('msglists')
    if (!msglists) {
      msglists = [];
    }
    this.data.msglists = msglists;
    this.setData(this.data)
    console.log(msglists)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})